﻿using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class _Default : System.Web.UI.Page 
{
    LoginBLL lg = new LoginBLL();
    
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(TextBox1.Text);
        int pass = Convert.ToInt32(TextBox2.Text);
        int a = lg.Login(id, pass);
        if (a == 0)
        {
            int b = lg.CheckUserId(id);
            if (b == 1)
            {
                    Application["count"] = (Application["count"] == null) ? 1 : (int)Application["count"] + 1;
                    if ((int)Application["count"] == 3)
                    {
                        lg.Lock_Acc(id);
                        Application["count"] = null;
                    }
                    if (Application["count"] != null)
                    {
                        Response.Write("Ban da dang nhap sai" + Application["count"].ToString());
                    }
            }
            else {
                Response.Write("Tk k ton tai");
            }           
        }
        else if (a == 1)
        {
            Response.Redirect("admin.aspx?UserId=" + TextBox1.Text.ToUpper());
        }
        else if (a == 2)
        {
            Response.Redirect("user.aspx?UserId=" + TextBox2.Text.ToUpper());
        }
    }
}
